package com.cby.widget.sample.ext

import android.view.LayoutInflater
import androidx.activity.ComponentActivity
import androidx.viewbinding.ViewBinding

/**
 * @description: ViewBindingExt
 *
 * @author ChenBaoyang
 * @date 8/9/21 14:06
 */

inline fun <reified VB: ViewBinding> ComponentActivity.binding() = lazy{
    inflateBinding<VB>(this.layoutInflater).also {
        setContentView(it.root)

    }
}


/**
 * 拓展内联函数：同个Java的类反射方法，
 * 实现：ActivityViewBindTestBinding.inflate(LayoutInflater.from(this@TestViewBindActivity))
 * @param layoutInflater LayoutInflater
 * @return VB
 */
inline fun <reified VB: ViewBinding> inflateBinding(layoutInflater: LayoutInflater) : VB {
    return VB::class.java.getMethod("inflate", LayoutInflater::class.java).invoke(null, layoutInflater) as VB
}

